package com.shali.cloud.controller;

import java.util.Arrays;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import com.shali.cloud.entity.User;

/**
 * 使用restTemplate时，如果要获得一个List，应该用数组，而不应该直接用List   !important
 * @author shali
 *
 */
@RestController
public class MovieController {

	@Autowired
	private RestTemplate restTemplate;
	
	@GetMapping("/list-all")
	public List<User> listAll() {
		//wrong
		//List<User> userList = this.restTemplate.getForObject("http://microservice-provider-user/list-all", List.class);
//		for (User user : userList) {
//			System.out.println(user.getId());
//		}
		//right
		User[] users = this.restTemplate.getForObject("http://microservice-provider-user/list-all", User[].class);
		List<User> userList = Arrays.asList(users);
		for (User user : userList) {
			System.out.println(user.getId());
		}
		return userList;
	}
}
